log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\D'HAULTFOEUILLE Files\DATAVERSE FILES\TABLE5.smcl", replace
set matsize 10000

use "\\file\UsersW$\wrr15\Home\My Documents\My Files\D'HAULTFOEUILLE Files\DATAVERSE FILES\GentzkowData.dta", clear

sort cnty90 year
xtset cnty90 year

// Notice that Gb_placebo and Gf_placebo are only defined for those groups whose treatment is stable between T-2 nd T-1

gen G_T = .
gen Gb_placebo = .
forvalue i=1872(4)1928 {
replace G_T =(changedailies>0)-(changedailies<0) if (year==`i')& mainsample==1
replace Gb_placebo = G_T if (numdailies[_n-2]==numdailies[_n-1]) & (year[_n-2]==year[_n-1]-4)
} 

gen G_T_for = G_T[_n+1]
gen Gf_placebo = Gb_placebo[_n+1]

// W-TC estimate with cluster-robust standard errors

set seed 1
fuzzydid prestout G_T G_T_for year numdailies, tc newcateg(0 1 2 1000) qualitative(st1-st48) cluster(cnty90) 

// This section corresponds to the placebo analysis
gen prestout_l1=l4.prestout

// W-TC-placebo estimate with cluster-robust standard errors for groups whose treatment is stable between T-2 and T-1

set seed 1
fuzzydid prestout_l1 Gb_placebo Gf_placebo year numdailies, tc newcateg(0 1 2 1000) qualitative(st1-st48) breps(100) cluster(cnty90) 

// W-TC estimate with cluster-robust standard errors on subsample of groups whose treatment is stable between T-2 and T-1

set seed 1
fuzzydid prestout Gb_placebo Gf_placebo year numdailies, tc newcateg(0 1 2 1000) qualitative(st1-st48) breps(100) cluster(cnty90) 

log close
